package war2100.game.states;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.GameState;
import org.newdawn.slick.state.StateBasedGame;

import TWLSlick.BasicTWLGameState;

import war2100.Game;
import war2100.game.states.menu.ExitHandler;
import war2100.game.states.menu.MenuButton;
import war2100.game.states.menu.StartGameHandler;
import war2100.game.states.menu.StartLobbyHandler;

public class MainMenuGameState extends BasicGameState implements GameState {
	private MenuButton startGame;
	private MenuButton startLobby;
	private MenuButton exit;
	private int currentMenuIndex;
	
	public static final int ID = 0;

	@Override
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
		currentMenuIndex = 0;
		if (sbg instanceof Game) {
			Game game = (Game) sbg;

			startGame = new MenuButton(gc, "Spiel starten", currentMenuIndex++, new StartGameHandler(game));
			startLobby = new MenuButton(gc, "Lobby starten", currentMenuIndex++, new StartLobbyHandler(game));
			exit = new MenuButton(gc, "Beenden", currentMenuIndex++, new ExitHandler());
		}
	}

	@Override
	public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException {
		startGame.render(gc, g);
		startLobby.render(gc, g);
		exit.render(gc, g);
	}

	@Override
	public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException {
		boolean clicked = gc.getInput().isMousePressed(Input.MOUSE_LEFT_BUTTON);
		
		startGame.update(gc, delta, clicked);
		startLobby.update(gc, delta, clicked);
		exit.update(gc, delta, clicked);
	}

	@Override
	public int getID() {
		return ID;
	}

}
